<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript" src="${ctx}/js/jquery.itextclear.js"></script>
<script type="text/javascript" src="${ctx}/js/employee.js"></script>
<script type="text/javascript" src="${ctx}/js/global_util.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="${ctx}/css/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="${ctx}/lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="${ctx}/lib/datatables/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="${ctx}/js/ajaxupload_tx.3.6.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.3.custom.min.js"></script>
<script type="text/javascript" src="js/flexigrid.js"></script>
<link href="${ctx}/css/black-tie/jquery-ui-1.7.3.custom.css"
      rel="stylesheet" type="text/css"/>
<!--<script type="text/javascript">
$(document).ready(function() {
$('#example').dataTable({
"sPaginationType": "full_numbers"
});
});
</script> -->
<!-- DATATABLES CSS END -->

<!--<script>
$(document).ready(function() {
$('#simple-button').popover('#simple-popover', {});
$('#top-button').popover('#top-popover', {preventLeft: true, preventRight: true, preventBottom:true});
});
</script>
-->
<h1 class="page-title">添加员工资料详细信息</h1>

<div class="container_12 clearfix leading">


<div class="grid_12">
<!-- wizard -->
<form id="staffcreate_form" class="wizard" method="post">
<nav>
    <ul class="clearfix">
        <li class="active"><strong>1.</strong> 公用属性</li>
        <li><strong>2.</strong> 私用属性</li>
        <li><strong>3.</strong> 教育情况</li>
        <li><strong>4.</strong> 培训情况</li>
        <li><strong>5.</strong> 工作经历</li>
        <li><strong>6.</strong> 家庭情况</li>
        <li><strong>7.</strong> 完成</li>
    </ul>
</nav>

<div class="items">

<!-- page1 -->
<section>

    <header>
        <h2>
            <strong>步骤 1: </strong> 输入员工公司属性信息
            <em>Enter the employees' basic information:</em>
        </h2>
    </header>

    <section>
        <ul class="clearfix">
            <li class="required double">

                <label>
                    照片 <span>*</span><br/>
                    <img width="120" height="135" src="images/Avatar.jpg" id="image_upload">
                </label>

                <label>
                    姓名 <span>*</span><br/>
                    <input type="text" class="full" name="employeeinfoBase.name" required/>
                </label>
                <label>
                    性别 <span>*</span><br/>
                    <select id="sex" name="employeeinfoBase.sex" class="full" required="required">
                        <option value="">-- 请选择 --</option>
                        <option value="0">先生</option>
                        <option value="1">女士</option>
                    </select>
                </label>
                <label>
                    ERP工号 <span>*</span><br/>
                    <input type="text" class="full" id="salaryNo_input" name="employeeinfoBase.salaryNo" onblur="checkSalaryNo(this)"/>
                </label>
            </li>
            <div class="clear">
                <input type="hidden" name="employeeinfoBase.facePath" id="emp_facePath">
            </div>
            <li class="required triple">
                <label>
                    员工工号 <span>*</span><br/>
                    <input name="employeeinfoWork.workNo" id="employeeWorkNo" type="text" value="" readonly="readonly"
                           required
                           class="full"/>
                </label>
                <label>
                    入司时间 <span>*</span><br/>
                    <input type="text" id="enterDate" name="employeeinfoBase.entryDate" class="full"
                           onclick="WdatePicker()" required/>
                </label>
                <label>
                    部门 <span>*</span><br/>
                    <%--
                    <select id="org_sel" name="employeeinfoWork.organization.id" required>
                        <s:iterator value="#request.organizations" var="org" status="st">
                            <s:if test="#st.index == 0 && #request.organizationId < 0">
                                <option value="${org.id}" selected="selected">${org.fullName}</option>
                            </s:if>
                            <s:elseif test="#request.organizationId == #org.id">
                                <option value="${org.id}" selected="selected">${org.fullName}</option>
                            </s:elseif>
                            <s:else>
                                <option value="${org.id}">${org.fullName}</option>
                            </s:else>
                        </s:iterator>
                    </select>
                    --%>
                    <input name="employeeinfoWork.organization.id" type="hidden" id="org_sel"
                           value="${organizationId}"/>
                    <select name="sel_area" id="sel_area_up" onchange="loadDutyByOrgId(this.value)"></select>
                </label>
            </li>

            <li class="required triple">
                <label>
                    职务 <span>*</span><br/>

                    <select id="duty_sel" name="employeeinfoWork.duty.id" style="opacity: 0;"
                            onchange="loadGradeByDutyId(this.value)" required>
                        <option value="-1">所有岗位</option>
                    </select>
                </label>

                <label>
                    职等 <span>*</span><br/>
                    <select id="grade_sel" name="employeeinfoWork.grade.id" required>

                    </select>
                </label>

                <label>
                    职级 <span>*</span><br/>
                    <select id="gv_sel" name="employeeinfoWork.gradeLevel.id" required>
                        
                    </select>
                </label>
            </li>
            <!-- username --><!-- password -->
        </ul>


    </section>

    <footer class="clearfix">
        <button type="button" class="next fr" onclick="checkOrg()">下一步 &raquo;</button>
    </footer>

</section>

<!-- page2 -->
<section>

<header>
    <h2>
        <strong>步骤 2: </strong> 输入员工个人属性信息 <b></b>
        <em>Enter the staff for more information:</em>
    </h2>
</header>

<section>
<ul class="clearfix">
<!-- address -->
<li class="required ftimes">
    <label>
        出生年月 <br/>
        <input type="text" id="birthday" name="employeeinfoBase.birthday" class="full" onfocus="WdatePicker
()"/>
    </label>
    <label>
        户籍地址 <br/>
        <input type="text" class="full" name="employeeinfoBase.census"/>
    </label>
    <label>
        身份证 <br/>
        <input type="text" class="full" name="employeeinfoBase.idcard"/>
    </label>
    <label>
        名族 <br/>
        <input type="text" class="full" name="employeeinfoBase.folk"/>
    </label>
</li>
<li class="required ftimes">
    <label>
        身高 <br/>
        <input type="text" class="full" name="employeeinfoBase.stature"/>
    </label>
    <label>
        档案所在地 <br/>
        <input type="text" class="full" name="employeeinfoBase.archives"/>
    </label>
    <label>
        左眼视力 <br/>
        <input type="text" class="full" name="employeeinfoBase.eyeLeft"/>
    </label>
    <label>
        右眼视力 <br/>
        <input type="text" class="full" name="employeeinfoBase.eyeRight"/>
    </label>
</li>
<li class="required ftimes">
    <label>
        体重 <br/>
        <input type="text" class="full" name="employeeinfoBase.avoirdupois"/>
    </label>
    <label>
        联系地址 <br/>
        <input type="text" class="full" name="employeeinfoBase.address"/>
    </label>
    <label>
        电话 <br/>
        <input type="text" class="full" name="employeeinfoBase.tel"/>
    </label>
    <label>
        住所邮编 <br/>
        <input type="text" class="full" name="employeeinfoBase.postcode"/>
    </label>

</li>
<li class="required ftimes">
    <label>
        邮箱 <br/>
        <input type="text" id="employee_email" onblur="IsMail(this.value)" class="full" name="employeeinfoBase.email"/>
    </label>
    <label>
        手机 <br/>
        <input type="text" class="full" name="employeeinfoBase.handSet"/>
    </label>
    <label>
        婚否 <br/>
        <select name="employeeinfoBase.marry" class="full">
            <option value="">-- 请选择 --</option>
            <option value="0">未婚</option>
            <option value="1">已婚</option>
        </select>
    </label>
    <label>
        入职期望薪资 <br/>
        <input type="text" class="full" name="employeeinfoBase.compensation"/>
    </label>

</li>
<li class="required ftimes">
    <label>
        英语阅读 <br/>
        <select name="employeeinfoBase.englishRead" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1">一般</option>
            <option value="2">熟练</option>
            <option value="3">精通</option>
        </select>
    </label>
    <label>
        其他语言阅读 <br/>
        <select name="employeeinfoBase.languageRead" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1">一般</option>
            <option value="2">熟练</option>
            <option value="3">精通</option>
        </select>
    </label>
    <label>
        英语证书 <br/>
        <select name="employeeinfoBase.englishLetter" class="full">
            <option value="">-- 请选择 --</option>
            <option value="3">三级</option>
            <option value="4">四级</option>
            <option value="6">六级</option>
            <option value="8">八级</option>
        </select>
    </label>
    <label>
        学历 <br/>
        <select name="employeeinfoBase.certificate" style="opacity: 0;" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1">小学</option>
            <option value="2">初中</option>
            <option value="3">高中</option>
            <option value="4">大专</option>
            <option value="5">本科</option>
            <option value="6">硕士</option>
            <option value="7">博士</option>
            <option value="8">博士后</option>
        </select>
    </label>
</li>
<li class="required ftimes">
    <label>
        英语书写 <br/>
        <select name="employeeinfoBase.englishWrite" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1">一般</option>
            <option value="2">熟练</option>
            <option value="3">精通</option>
        </select>
    </label>
    <label>
        其他语言书写 <br/>
        <select name="employeeinfoBase.languageWrite" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1">一般</option>
            <option value="2">熟练</option>
            <option value="3">精通</option>
        </select>
    </label>
    <label>
        子女 <br/>
        <select name="employeeinfoBase.baby" class="full">
            <option value="">-- 请选择 --</option>
            <option value="0">无</option>
            <option value="1">有</option>
        </select>
    </label>
    <label>
        技能熟练度 <br/>
        <select name="employeeinfoBase.tech" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1">多能工</option>
            <option value="2">傅级</option>
            <option value="3">熟手</option>
            <option value="4">半熟手</option>
            <option value="5">时装熟手</option>
            <option value="6">一般</option>
            <option value="7">生手</option>
        </select>
    </label>

</li>
<li class="required ftimes">
    <label>
        英语会话 <br/>
        <select name="employeeinfoBase.englishDialog" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1">一般</option>
            <option value="2">熟练</option>
            <option value="3">精通</option>
        </select>
    </label>
    <label>
        其他语言会话 <br/>
        <select name="employeeinfoBase.languageDialog" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1">一般</option>
            <option value="2">熟练</option>
            <option value="3">精通</option>
        </select>
    </label>
    <label>
        员工状态 <br/>
        <select name="employeeinfoBase.state" class="full">
            <option value="">-- 请选择 --</option>
            <option value="1" selected>在职</option>
            <option value="2">离职</option>
            <option value="3">人才库</option>
        </select>
    </label>
    <label>
        其他说明事项 <br/>
        <input type="text" class="full" name="employeeinfoBase.remark"/>
    </label>


</li>

<!-- zip / city -->
</ul>
</section>

<footer class="clearfix">
    <button type="button" class="prev fl">&laquo; 上一步</button>
    <button type="button" class="next fr" onclick="checkForm();">下一步 &raquo;</button>
</footer>

</section>


<!-- page3 -->
<section>

    <header>
        <h2>
            <strong>步骤 3: </strong> 输入教育经历
            <em>教育经历</em>
        </h2>
    </header>

    <section>
        <div id="list_eduList">

        </div>
        <div class="portlet">
            <header>

            </header>
            <section class="clearfix">

                <div class="grid_12">
                    <dl>
                        <dt>学校名称</dt>
                        <dd>
                            <input type="text" id="eduSchoolname" name="employeeinfoEducation.schoolName" class="full"/>
                        </dd>
                        <dt>所学专业</dt>
                        <dd>
                            <input type="text" id="eduSpecialty" name="employeeinfoEducation.specialty" class="full"/>
                        </dd>
                        <dt>学位</dt>
                        <dd>
                            <input type="text" id="eduDegree" name="employeeinfoEducation.degree" class="full"/>
                        </dd>
                        <dt>时间</dt>
                        <dd>
                            开始<input type="text" id="eduBeginDate" name="employeeinfoEducation.beginDate"
                                     onfocus="WdatePicker({maxDate:$('#eduendDate').val()})" value="" style="width:30%">
                            结束<input type="text" id="eduendDate" name="employeeinfoEducation.endDate"
                                     onfocus="WdatePicker({minDate:$('#eduBeginDate').val()})" value=""
                                     style="width:30%">
                            <input type="hidden" id="edu_primary_id" name="employeeinfoEducation.id" value="">
                        </dd>


                    </dl>
                    <div class="form-action clearfix">
                        <p style="padding-top:10px">
                            <a class="button" href="#" onclick="submitEducation()"><span
                                    style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span><span
                                    id="add_item">新增项目</span></a>
                        </p>
                    </div>
                </div>


            </section>
        </div>
    </section>

    <footer class="clearfix">
        <button type="button" class="prev">&laquo; 上一步</button>
        <button type="button" class="next fr">下一步 &raquo;</button>
    </footer>

</section>

<!-- page4 -->
<section>

    <header>
        <h2>
            <strong>步骤 4: </strong> 输入培训情况
            <em>培训情况</em>
        </h2>
    </header>

    <section>

        <div id="list_trainList">


        </div>
        <div class="portlet">
            <header>

            </header>
            <section class="clearfix">
                <div class="grid_12">
                    <dl>
                        <dt>证书</dt>
                        <dd>
                            <input type="text" id="train_letter" name="employeeinfoTrain.letter" class="full"/>
                        </dd>
                        <dt>培训地点</dt>
                        <dd>
                            <input type="text" id="train_address" name="employeeinfoTrain.trainAddress" class="full"/>
                        </dd>

                        <dt>培训时间</dt>
                        <dd>
                            开始
                            <input type="text" id="train_beginDate" name="employeeinfoTrain.beginDate"
                                   onfocus="WdatePicker({maxDate:$('#train_endDate').val()})" style="width:30%">
                            结束
                            <input type="text" id="train_endDate" name="employeeinfoTrain.endDate"
                                   onfocus="WdatePicker({minDate:$('#train_beginDate').val()})" style="width:30%">
                            <input type="hidden" id="train_primary_id" name="employeeinfoTrain.id" value="">
                        </dd>
                        <dt>培训内容</dt>
                        <dd>
                            <textarea class="full" id="train_content" name="employeeinfoTrain.trainContent"
                                      required="required" rows="5" placeholder="请输入培训内容"></textarea>
                        </dd>

                    </dl>
                    <div class="form-action clearfix">
                        <p style="padding-top:10px">
                            <a class="button" href="#" onclick="submitTrain()"><span
                                    style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>新增项目</a>
                        </p>
                    </div>
                </div>


            </section>
        </div>
    </section>

    <footer class="clearfix">
        <button type="button" class="prev">&laquo; 上一步</button>
        <button type="button" class="next fr">下一步 &raquo;</button>
    </footer>

</section>


<!-- page5 -->
<section>

    <header>
        <h2>
            <strong>步骤 5: </strong> 输入工作经历
            <em>工作经历</em>
        </h2>
    </header>

    <section>

        <div id="employee_exp">

        </div>
        <div class="portlet">
            <header>

            </header>
            <section class="clearfix">
                <div class="grid_12">
                    <dl>
                        <dt>公司名称</dt>
                        <dd>
                            <input type="text" id="exp_company" name="employeeWorkExperience.compname" class="full"/>
                        </dd>
                        <dt>职位</dt>
                        <dd>
                            <input type="text" id="exp_position" name="employeeWorkExperience.job" class="full"/>
                        </dd>

                        <dt>工作时间</dt>
                        <dd>
                            开始
                            <input type="text" id="exp_beginDate" name="employeeWorkExperience.beginDate"
                                   onfocus="WdatePicker({maxDate:$('#exp_endDate').val()})" style="width:30%">
                            结束
                            <input type="text" id="exp_endDate" name="employeeWorkExperience.endDate"
                                   onfocus="WdatePicker({minDate:$('#exp_beginDate').val()})" style="width:30%">
                            <input type="hidden" id="exp_primary_id" name="employeeWorkExperience.id" value="">
                        </dd>
                        <dt>月薪</dt>
                        <dd>
                            <input type="text" id="exp_pay" name="employeeWorkExperience.monthlyPay" class="full"/>
                        </dd>
                        <dt>证明人</dt>
                        <dd>
                            <input type="text" id="exp_prover" name="employeeWorkExperience.proveMan" class="full"/>
                        </dd>
                        <dt>联系电话</dt>
                        <dd>
                            <input type="text" id="exp_contel" name="employeeWorkExperience.contel" class="full"/>
                        </dd>
                        <dt>离职原因</dt>
                        <dd>
                            <textarea class="full" id="exp_reason" name="employeeWorkExperience.resignReason"
                                      required="required" rows="5" placeholder="请输入离职原因"></textarea>
                        </dd>

                    </dl>
                    <div class="form-action clearfix">
                        <p style="padding-top:10px">
                            <a class="button" href="#" onclick="submitExperience()"><span
                                    style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>新增项目</a>
                        </p>
                    </div>
                </div>

            </section>
        </div>
    </section>

    <footer class="clearfix">
        <button type="button" class="prev">&laquo; 上一步</button>
        <button type="button" class="next fr">下一步 &raquo;</button>
    </footer>

</section>


<!-- page6 -->
<section>

    <header>
        <h2>
            <strong>步骤 6: </strong> 输入家庭情况
            <em>家庭情况</em>
        </h2>
    </header>

    <section>

        <div id="employee_family">

        </div>
        <div class="portlet">
            <header>

            </header>
            <section class="clearfix">
                <div class="grid_12">
                    <dl>
                        <dt>家庭关系</dt>
                        <dd>
                            <input type="text" id="familyRelation" name="employeeinfoFamily.familyRelation"
                                   class="full"/>
                        </dd>
                        <dt>工作单位</dt>
                        <dd>
                            <input type="text" id="workCompany" name="employeeinfoFamily.compname" class="full"/>
                        </dd>
                        <dt>姓名</dt>
                        <dd>
                            <input type="text" id="fname" name="employeeinfoFamily.name" class="full"/>
                        </dd>
                        <dt>住宅地址</dt>
                        <dd>
                            <input type="text" id="faddress" name="employeeinfoFamily.address" class="full"/>
                        </dd>
                        <dt>紧急联系人</dt>
                        <dd>
                            <input type="text" id="furgentContactor" name="employeeinfoFamily.exigenceConname"
                                   class="full"/>
                        </dd>
                        <dt>紧系联系人关系</dt>
                        <dd>
                            <input type="text" id="furgentRelation" name="employeeinfoFamily.exigenceRelation"
                                   class="full"/>
                        </dd>
                        <dt>紧急联系人电话</dt>
                        <dd>
                            <input type="text" id="furgentTel" name="employeeinfoFamily.contel" class="full"/>
                            <input type="hidden" id="family_primary_id" name="employeeinfoFamily.id" value="">
                        </dd>

                    </dl>
                    <div class="form-action clearfix">
                        <p style="padding-top:10px">
                            <a class="button" href="#" onclick="saveFamily()"><span
                                    style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>新增项目</a>
                        </p>
                    </div>
                </div>


            </section>
        </div>
    </section>

    <footer class="clearfix">
        <button type="button" class="prev">&laquo; 上一步</button>
        <button type="button" class="next fr" onclick="submitOver()">下一步 &raquo;</button>
    </footer>

</section>
<!-- page7 -->
<section>

    <header>
        <h2>
            <strong>步骤 7: </strong> 完成!
            <em>员工：<span id="staff_add_userName"></span>的信息已经成功录入系统.</em>
        </h2>
    </header>

    <section>
        <h3>本次录入用时<span id="staff_add_totalTime"></span>!</h3>
    </section>

    <footer class="clearfix">
        <!--<button type="button" class="prev">&laquo; 上一步</button>-->
        <button type="button" class="prev"
                onclick="javascript:window.location.href='#employee/staff.xhtml'">&laquo; 录入新的员工资料
        </button>
    </footer>

</section>

</div>
<!--items-->

</form>
<!--wizard-->

</div>
</div>
<div class="clear"></div>
<!-- WIZARD SETUP -->
<!-- 员工选择层 -->
<div id="employee_dialog" title="选择推荐人员">
    <div class="clearfix">
        <table id="employee_table" style="display: none;"></table>
        <div class="clearfix"></div>
    </div>
</div>

<script type="text/javascript" src="${ctx}/js/jquery.wizard.js"></script>
<script type="text/javascript">
function checkOrg() {
    if($("#salaryNo_input").val().length == 0){
        alert("请输入考勤工号")
        return;
    }
    if ($("#org_sel").attr("value") == -1) {
        alert("未选择组织结构，请先添加组织结构");
        return;
    }
    if ($("#duty_sel").children().length == 0) {
        alert("该组织结构没有职务，请先添加职务");
        return;
    }

    if ($("#grade_sel").children().length == 0) {
        alert("该职务没有职等，请先添加职等");
        return;
    }

}

$(function() {
    $('.wizard').wizard();

    AjaxUpload.init('${ctx}/file/upload.xhtml', "image_upload", "", "");

    setTimeout('generateWorkNoByOrgId(${organizationId})', 600);

});
$(document).ready(function () {
    //bind event to org_sel
    //    $("#org_sel").change(function () {
    //        loadDutyByOrgId($("#org_sel").val());
    //    })
    //    $("#duty_sel").change(function () {
    //        loadGradeByDutyId($("#duty_sel").val());
    //    });
        $("#grade_sel").change(function () {
            loadGradeLevelByDutyId($("#duty_sel").val(), $("#grade_sel").find("option:selected").text());
        });
    if ($("#org_sel").attr("value") != -1) {
        fillLevelOrgSel($("#org_sel").attr("value"));
    }
});

function generateWorkNoByOrgId(orgId) {
    $.ajax({
        type:"get",
        url:"/ajax/retrive_workno.xhtml?organizationId=" + orgId,
        dataType:"json",
        cache:false,
        success:function (data) {
            if (data == null) {
                alert('请先添加员工工号设置');
            } else {
                $("#employeeWorkNo").val(data);
            }
        }
    });
}
/**
 * load the duty list
 * */
function loadDutyByOrgId(orgId) {
    //load the duty
    $("#duty_sel").html("");
    $("#duty_sel").prev().html("");
     $("#org_sel").attr("value",orgId);
    $.ajax({
        type:"get",
        url:"/ajax/duty-list.xhtml?organizationId=" + orgId,
        //data: "name=John&location=Boston",
        dataType:"json",
        success:function (data) {
            var strHTML = "";
            if (data != null && data.length > 0) {
                $.each(data, function (i, duty) {
                    strHTML += "<option value=\"" + duty.id + "\"" + (i == 0 ? " selected='selected'" : "") + ">" + duty.dutyName + "</option>";
                });

                $("#duty_sel").append(strHTML);
                $("#duty_sel").prev().html($("#duty_sel").find("option:selected").text());
            }
            // load the grade list
            loadGradeByDutyId($("#duty_sel").val());
        }
    });
}

/**
 * load the grade level
 */
function loadGradeByDutyId(dutyId) {
    if(dutyId==-1){
        return;
    }
    $("#grade_sel").html("");
    $("#grade_sel").prev().html("");
    $.ajax({
        type:"get",
        url:"/ajax/grade_list.xhtml?dutyId=" + dutyId,
        //data: "name=John&location=Boston",
        dataType:"json",
        success:function (data) {
            var strHTML = "";
            if (data != null && data.length > 0) {
                $.each(data, function (i, grade) {
                    strHTML += "<option value=\"" + grade.id + "\"" + (i == 0 ? " selected='selected'" : "") + ">" + grade.gradeName + "</option>";
                });

                $("#grade_sel").append(strHTML);
                $("#grade_sel").prev().html($("#grade_sel").find("option:selected").text());
            }
            //load the grade level list
            loadGradeLevelByDutyId($("#duty_sel").val(), $("#grade_sel").find("option:selected").text());
        }
    });
}

/**
 * 加载职级列表
 */
function loadGradeLevelByDutyId(dutyId, gradeName) {
    $("#gv_sel").html("");
    $("#gv_sel").prev().html("");
    $.ajax({
        type:"POST",
        url:"/ajax/grade_lvlist.xhtml",
        data:{"dutyId":dutyId, "gradeName":gradeName},
        dataType:"json",
        success:function (data) {
            var strHTML = "";
            if (data != null && data.length > 0) {
                $.each(data, function (i, grade) {
                    strHTML += "<option value=\"" + grade.id + "\"" + (i == 0 ? " selected='selected'" : "") + ">" + grade.gradeSort + "</option>";
                });
                $("#gv_sel").append(strHTML);
                $("#gv_sel").prev().html($("#gv_sel").find("option:selected").text());
            }
        }
    });
}
function onUploadSubmit(file, ext) {
    //    if(ext!="png" || ext!="jpg"){
    //        alert("上传文件格式不正确");
    //        return;
    //    }
    //    alert("file=" + file + ", ext=" + ext)
}
function onUploadComplete(file, response) {
    //{"message":"filePath","result":"F:\\Projects\\ehr\\src\\main\\webapp\\WEB-INF\\pages\\temp\\2012-06-26\\1340725945119_Qaga_1101134.jpg","success":true}
    //alert("file=" + file + ":" + response)
    var d;
    try {
        d = eval("[" + response + "]");
    }
    catch(err) {
        alert("文件上传错误！");
        return;
    }

    //var message = d[0].message;
    //上传出错
    if (d[0].success == false) {
        alert("上传出错")
        return;
    }
    //上传成功
    else {
        var realPath = d[0].result;
        //alert(realPath);
        $("#image_upload").attr("src", realPath);
        $("#emp_facePath").val(realPath);
        //alert("上传成功")
    }
}

function checkUpload() {
    alert('aaa');
    //        var file = $name("#staffcreate_form").value;
    //                                                  alert(file);
    //			if(file == null || file == ""){
    //				alert("请选择上传头像");
    //				return ;
    //			}
    //
    //			var extend = file.substr(file.length-3);//文件扩展名
    //			if(extend != "jpg"){
    //				alert("上传头像格式不对");
    //				return ;
    //			}

    var url = "/file/upload.xhtml";
    $.ajax(url, {
        type:"POST",
        data:$("#photo_form").serialize(),
        dataType:"html",
        cache:false,
        success:function(a) {
            alert("上传成功");
        },
        complete:function(b) {
        }
    });
}
function checkForm() {
    var url = "${ctx}/employee/staff_create.xhtml";
    $.ajax(url, {
        type:"POST",
        data:$("#staffcreate_form").serialize(),
        dataType:"html",
        cache:false,
        success:function(a) {
            //return pageDownloaded(a,url)
        },
        complete:function(b) {
        }
    });
}

function submitEducation() {
    if (checkNull($("#eduSchoolname").attr("value"))) {
        alert("学校名称不能为空");
        return;
    }

    if (checkNull($("#eduSpecialty").attr("value"))) {
        alert("所学专业不能为空");
        return;
    }

    if (checkNull($("#eduDegree").attr("value"))) {
        alert("学位不能为空");
        return;
    }

    if (checkNull($("#eduBeginDate").attr("value"))) {
        alert("开始时间不能为空");
        return;
    }

    if (checkNull($("#eduendDate").attr("value"))) {
        alert("结束时间不能为空");
        return;
    }
    var url = "${ctx}/employee/edu_list.xhtml";
    $.ajax(url, {
        type:"POST",
        data:$("#staffcreate_form").serialize(),
        dataType:"html",
        cache:false,
        success:function(a) {
            $("#list_eduList").html("");
            $("#list_eduList").html(a);

            $("#eduSchoolname").val("");
            $("#eduSpecialty").val("");
            $("#eduDegree").val("");
            $("#eduBeginDate").val("");
            $("#eduendDate").val("");
            $("#edu_primary_id").val("");
            //修正上一步下一步div hideen bug.
            $("#staffcreate_form").css("height", $("#staffcreate_form").height() + 110);
        },
        complete:function() {

        }
    });
}
function submitTrain() {
    if (checkNull($("#train_letter").attr("value"))) {
        alert("请输入培训证书");
        return;
    }
    if (checkNull($("#train_address").attr("value"))) {
        alert("请输入培训地点");
        return;
    }
    if (checkNull($("#train_beginDate").attr("value"))) {
        alert("请输入培训开始时间");
        return;
    }
    if (checkNull($("#train_endDate").attr("value"))) {
        alert("请输入培训结束时间");
        return;
    }
    if (checkNull($("#train_content").attr("value"))) {
        alert("请输入培训内容");
        return;
    }
    var url = "${ctx}/employee/train_list.xhtml";
    $.ajax(url, {
        type:"POST",
        data:$("#staffcreate_form").serialize(),
        dataType:"html",
        cache:false,
        success:function(a) {
            $("#list_trainList").html("");
            $("#list_trainList").html(a);
            //清空培训表单数据
            $("#train_letter").val("");
            $("#train_address").val("");
            $("#train_content").val("");
            $("#train_beginDate").val("");
            $("#train_endDate").val("");
            $("#train_primary_id").val("");
            $("#staffcreate_form").css("height", $("#staffcreate_form").height() + 110);
        },
        complete:function() {
        }
    });
}
function submitExperience() {
    if (checkNull($("#exp_company").attr("value"))) {
        alert("请输入公司名称");
        return;
    }
    if (checkNull($("#exp_position").attr("value"))) {
        alert("请输入职位");
        return;
    }
    if (checkNull($("#exp_beginDate").attr("value"))) {
        alert("请输入工作开始时间");
        return;
    }
    if (checkNull($("#exp_endDate").attr("value"))) {
        alert("请输入工作结束时间");
        return;
    }
    if (checkNull($("#exp_pay").attr("value"))) {
        alert("请输入月薪");
        return;
    }
    if (checkNull($("#exp_prover").attr("value"))) {
        alert("请输入证明人");
        return;
    }
    if (checkNull($("#exp_contel").attr("value"))) {
        alert("请输入证明人");
        return;
    }
    if (checkNull($("#exp_reason").attr("value"))) {
        alert("请输入离职原因");
        return;
    }
    var url = "${ctx}/employee/exp_list.xhtml";
    $.ajax(url, {
        type:"POST",
        data:$("#staffcreate_form").serialize(),
        dataType:"html",
        cache:false,
        success:function(a) {
            $("#employee_exp").html("");
            $("#employee_exp").append(a);
            //解决上一步，下一步隐藏的bug
            $("#staffcreate_form").css("height", $("#staffcreate_form").height() + 220);
            //清空表单数据
            $("#exp_position").val("");
            $("#exp_company").val("");
            $("#exp_beginDate").val("");
            $("#exp_endDate").val("");
            $("#exp_pay").val("");
            $("#exp_prover").val("");
            $("#exp_contel").val("");
            $("#exp_reason").val("");
            $("#exp_primary_id").val("");
        },
        complete:function() {

        }
    });
}
function saveFamily() {
    if (checkNull($("#familyRelation").attr("value"))) {
        alert("请输入家庭关系");
        return;
    }
    if (checkNull($("#workCompany").attr("value"))) {
        alert("请输入工作单位");
        return;
    }
    if (checkNull($("#fname").attr("value"))) {
        alert("请输入姓名");
        return;
    }
    if (checkNull($("#faddress").attr("value"))) {
        alert("请输入住宅地址");
        return;
    }
    if (checkNull($("#furgentContactor").attr("value"))) {
        alert("请输入紧急联系人");
        return;
    }
    if (checkNull($("#furgentRelation").attr("value"))) {
        alert("请输入紧急联系人关系");
        return;
    }
    if (checkNull($("#furgentTel").attr("value"))) {
        alert("请输入紧急联系人电话");
        return;
    }
    var url = "${ctx}/employee/family_list.xhtml";
    $.ajax(url, {
        type:"POST",
        data:$("#staffcreate_form").serialize(),
        dataType:"html",
        cache:false,
        success:function(a) {
            $("#employee_family").html("");
            $("#employee_family").append(a);
            $("#familyRelation").val("");
            $("#workCompany").val("");
            $("#fname").val("");
            $("#faddress").val("");
            $("#furgentContactor").val("");
            $("#furgentRelation").val("");
            $("#furgentTel").val("");
            $("#family_primary_id").val("");

            $("#staffcreate_form").css("height", $("#staffcreate_form").height() + 220);
        },
        complete:function() {
        }
    });
}

function submitOver() {
    var url = "${ctx}/employee/staff_over.xhtml";
    $.ajax(url, {
        type:"POST",
        data:$("#staffcreate_form").serialize(),
        dataType:"json",
        cache:false,
        success:function(pojo) {
            $("#staff_add_userName").html(pojo.userName);
            $("#staff_add_totalTime").html(pojo.usedTime);
        },
        complete:function() {
        }
    });
}
function openSelectBtn() {
    $("#selectedBtn").attr("disabled", "");
}

function closeSelectBtn() {
    $("#selectedBtn").attr("disabled", "disabled");
}

//删除教育情况
function eduDelete(obj) {
    if (confirm("你确定要删除吗？")) {
        var url = "${ctx}/ajax/relate_delete.xhtml";
        $.ajax(url, {
            type:"POST",
            data:{"id":obj,"state":1},
            dataType:"html",
            cache:false,
            success:function(a) {
                var con = $("#edu_" + obj);
                con.hide();
                $("#staffcreate_form").css("height", $("#staffcreate_form").height() - 110);
                $("#eduSchoolname").val("");
                $("#eduSpecialty").val("");
                $("#eduDegree").val("");
                $("#eduBeginDate").val("");
                $("#eduendDate").val("");
            },
            complete:function() {

            }
        });
    }

}
//修改教育情况
function eduModify(obj) {
    var url = "${ctx}/employee/getEduinfoById.xhtml?eduId=" + obj;
    $.ajax(url, {
        type:"POST",
        dataType:"json",
        cache:false,
        success:function(edu) {
            if (edu != null) {
                $("#eduSchoolname").val(edu.schoolName);
                $("#eduSpecialty").val(edu.specialty);
                $("#eduDegree").val(edu.degree);
                $("#eduBeginDate").val(edu.beginDateStr);
                $("#eduendDate").val(edu.endDateStr);
                $("#edu_primary_id").val(edu.id);  //edu_primary_id
                $("#edu_btn_" + obj).hide();
                $("#edu_" + obj).hide();
                $("#staffcreate_form").css("height", $("#staffcreate_form").height() - 110);
            }
        },
        complete:function() {
        }
    });
}

//删除培训经历
function trainDelete(obj) {
    if (confirm("你确定要删除吗？")) {
        var url = "${ctx}/ajax/relate_delete.xhtml";
        $.ajax(url, {
            type:"POST",
            data:{"id":obj,"state":2},
            dataType:"html",
            cache:false,
            success:function(a) {
                var con = $("#train_" + obj);
                con.hide();
                $("#staffcreate_form").css("height", $("#staffcreate_form").height() - 110);
                $("#train_letter").val("");
                $("#train_address").val("");
                $("#train_content").val("");
                $("#train_beginDate").val("");
                $("#train_endDate").val("");
            },
            complete:function() {
            }
        });
    }

}
function trainModify(obj) {
    var url = "${ctx}/employee/getTrainfoById.xhtml?eduId=" + obj;
    $.ajax(url, {
        type:"POST",
        dataType:"json",
        cache:false,
        success:function(train) {
            if (train != null) {
                $("#train_letter").val(train.letter);
                $("#train_address").val(train.trainAddress);
                $("#train_content").val(train.trainContent);
                $("#train_beginDate").val(train.beginDateStr);
                $("#train_endDate").val(train.endDateStr);
                $("#train_primary_id").val(train.id);  //train_primary_id
                $("#train_btn_" + obj).hide();
                $("#train_" + obj).hide();
                $("#staffcreate_form").css("height", $("#staffcreate_form").height() - 110);
            }
        },
        complete:function() {
        }
    });

}

//删除工作经历
function expDelete(obj) {
    if (confirm("你确定要删除吗？")) {
        var url = "${ctx}/ajax/relate_delete.xhtml"
        $.ajax(url, {
            type:"POST",
            data:{"id":obj,"state":3},
            dataType:"html",
            cache:false,
            success:function(a) {
                var con = $("#exp_" + obj);
                con.hide();
                $("#staffcreate_form").css("height", $("#staffcreate_form").height() - 110);
                $("#exp_position").val("");
                $("#exp_company").val("");
                $("#exp_beginDate").val("");
                $("#exp_endDate").val("");
                $("#exp_pay").val("");
                $("#exp_prover").val("");
                $("#exp_contel").val("");
                $("#exp_reason").val("");
            },
            complete:function() {
            }
        });
    }

}
function expModify(obj) {
    var url = "${ctx}/employee/getExperienceById.xhtml?eduId=" + obj;
    $.ajax(url, {
        type:"POST",
        dataType:"json",
        cache:false,
        success:function(exp) {
            if (exp != null) {
                $("#exp_position").val(exp.job);
                $("#exp_company").val(exp.compname);
                $("#exp_beginDate").val(exp.beginDateStr);
                $("#exp_endDate").val(exp.endDateStr);
                $("#exp_pay").val(exp.monthlyPay);
                $("#exp_prover").val(exp.proveMan);
                $("#exp_contel").val(exp.contel);
                $("#exp_reason").val(exp.resignReason);

                $("#exp_primary_id").val(exp.id);  //train_primary_id
                $("#exp_btn_" + obj).hide();
                $("#exp_" + obj).hide();
                $("#staffcreate_form").css("height", $("#staffcreate_form").height() - 110);
            }
        },
        complete:function() {
        }
    });
}
//删除家庭情况
function famDelete(obj) {
    if (confirm("你确定要删除吗？")) {
        var url = "${ctx}/ajax/relate_delete.xhtml"
        $.ajax(url, {
            type:"POST",
            data:{"id":obj,"state":4},
            dataType:"html",
            cache:false,
            success:function(a) {
                var con = $("#fam_" + obj);
                con.hide();
                $("#staffcreate_form").css("height", $("#staffcreate_form").height() - 110);
                $("#familyRelation").val("");
                $("#workCompany").val("");
                $("#fname").val("");
                $("#faddress").val("");
                $("#furgentContactor").val("");
                $("#furgentRelation").val("");
                $("#furgentTel").val("");

            },
            complete:function() {
            }
        });
    }

}
function famModify(obj) {
    var url = "${ctx}/employee/getFamilyById.xhtml?eduId=" + obj;
    $.ajax(url, {
        type:"POST",
        dataType:"json",
        cache:false,
        success:function(fam) {
            if (fam != null) {
                $("#familyRelation").val(fam.familyRelation);
                $("#workCompany").val(fam.compname);
                $("#fname").val(fam.name);
                $("#faddress").val(fam.address);
                $("#furgentContactor").val(fam.exigenceConname);
                $("#furgentRelation").val(fam.exigenceRelation);
                $("#furgentTel").val(fam.contel);

                $("#family_primary_id").val(fam.id);  //fam_primary_id
                $("#fam_btn_" + obj).hide();
                $("#fam_" + obj).hide();
                $("#staffcreate_form").css("height", $("#staffcreate_form").height() - 220);
            }
        },
        complete:function() {
        }
    });
}
//有推荐人的时候显示选择按钮
function showSelectEmp(obj) {
    if (obj == 1) {
        $("#introducer1").attr("checked", "checked");
        $("#introselectId").css("display", "none");

    } else {
        $("#introducer2").attr("checked", "checked");
        $("#introselectId").css("display", "");
        $("#selectintroducerId").attr("name", "employeeinfoWork.introducerId.id");
        $("#selectintroducerId").val(id);
    }
}


function IsMail(mail) {

    var patrn = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
    if (checkNull(mail))
        return;
    if (!patrn.test(mail)) {
        alert('email格式不正确');
        $("#employee_email").attr("value", "");
    }

}


var currentSelOrgId = -1;
function loadChildrenOrgsByTab(targetObj) {
    currentSelOrgId = targetObj.options[targetObj.selectedIndex].value;
    $(targetObj).prev().html($(targetObj).find("option:selected").text());
    $(targetObj).parent().nextAll().remove();
    if (currentSelOrgId != -1) {
        //load the organization uniform-sel_area
        $.ajax({
            type:"get",
            url:"/ajax/organization-top.xhtml?parentId=" + currentSelOrgId,
            //data: "name=John&location=Boston",
            dataType:"json",
            success:function (data) {
                if (data != null && data.length > 0) {
                    var strHTML = " <div id=\"uniform-sel-area-" + currentSelOrgId + "\" class=\"selector\">";
                    strHTML += "<span style=\"-moz-user-select: none;\">所有</span>";
                    strHTML += "<select id=\"sel_area-" + currentSelOrgId + "\" name=\"sel_area-" + currentSelOrgId + "\" style='opacity: 0;'>";
                    strHTML += "<option value=\"-1\">所有</option>";
                    $.each(data, function (i, org) {
                        strHTML += "<option value=\"" + org.id + "\">" + org.fullName + "</option>";
                    });
                    strHTML += "</select>";
                    $(targetObj).parent().after(strHTML);
                }
            }
        });
        $("#org_sel").attr("value", currentSelOrgId);
    }
    loadDutyByOrgId(currentSelOrgId);
}

function fillLevelOrgSel(parentId) {
    if (parentId != -1) {
        $.ajax({
            type:"get",
            url:"/ajax/organization-top.xhtml?parentId=" + parentId,
            //data: "name=John&location=Boston",
            dataType:"json",
            success:function (data) {
                if (data != null && data.length > 0) {
                    var strHTML = "";
                    $.each(data, function (i, org) {
                        if(org.id==parentId){
                            strHTML += "<option value=\"" + org.id + "\" selected='selected'>" + org.fullName + "</option>";
                        }else{
                           strHTML += "<option value=\"" + org.id + "\">" + org.fullName + "</option>";
                        }
                    });
                    $("#sel_area_up").append(strHTML);
                    $("#sel_area_up").prev().html($("#sel_area_up").find("option:selected").text());
                }
            }
        });
        loadDutyByOrgId(parentId)
    }

}

//add.wxn#2013.6.6：加入考勤工号
function checkSalaryNo(obj){
    var salaryNo = $(obj).val();
    if(salaryNo.length > 0){
        $.ajax({
            type:"post",
            url:"/ajax/check-salary-no.xhtml?name=" + salaryNo,
            //data: "name=John&location=Boston",
            dataType:"json",
            success:function (data) {
                if(data != true){
                    alert("考勤工号重复");
                    $("#salaryNo_input").val("");
                }
            }
        });
    }
}
</script>

<!-- WIZARD SETUP END -->

</body>
</html>